package stud.mpgame.net.command;

import org.apache.mina.core.buffer.IoBuffer;

import stud.mpgame.network.Message;
import stud.mpgame.network.UserObject;

import stud.mpgame.server.test.TestSnapshot;

import stud.mpgame.net.gameobject.TestGameObject;

import stud.mpgame.snapshot.ICommand;
import stud.mpgame.snapshot.ISnapshot;

public class TestCommand extends UserObject implements ICommand {
	
	private int time;
	private int newValue;
    private int userID;
	
	public TestCommand() {}

	public int getTime() {
		return time;
	}

    public int getUserID() {
        return userID;
    }

    public void apply(ISnapshot snapshot) {
        System.out.println("apply command: " + newValue);
		((TestGameObject) ((TestSnapshot) snapshot).getTestGameObject()).setValue(newValue);
	}

    @Override
    public void readExternal(IoBuffer buffer, Message owner) {
        time = buffer.getInt();
        newValue = buffer.getInt();
        this.userID = (Integer)owner.getFirstSession().getAttribute("userID");
    }

    @Override
    public String toString() {
        String result = "\n";
        result += "VALUE: " + newValue + "\n";
        return result;
    }

}
